package org.tang.schoolproject.controller;

import cn.dev33.satoken.util.SaResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.tang.schoolproject.entitys.Book;
import org.tang.schoolproject.service.BookService;

@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
public class BookController {
    private final BookService bookService;

    /**
     * 保存图书
     * @param files
     * @param book
     * @return
     */
    @PostMapping("/saveBook")
    public SaResult saveBook(@RequestPart("file") MultipartFile[] files, @RequestPart Book book){
        return bookService.saveBook(files, book);
    }

    /**
     * 根据id查询图书
     * @param id
     * @return
     */
    @GetMapping("/id")
    public SaResult getBookById(@RequestParam Long id){
        return bookService.getBookById(id);
    }

    /**
     * 保存图书内容
     * @param file
     * @param bookId
     * @return
     */
    @PostMapping("/saveBookContent")
    public SaResult saveBookContent(@RequestPart MultipartFile file,@RequestPart Long bookId){
        return bookService.saveBookContent(file, bookId);
    }

    /**
     * 修改图书
     * @param book
     * @return
     */
    @PostMapping("/updateBook")
    public SaResult updateBook(@RequestPart(value = "file",required = false) MultipartFile[] files, @RequestPart Book book){
        return bookService.updateBook(files,book);
    }

    /**
     * 修改图书内容
     * @param file
     * @return
     */
    @PostMapping("/updateBookContent")
    public SaResult updateBookContent(@RequestPart MultipartFile file,@RequestPart Long bookId){
        return bookService.updateBookContent(file, bookId);
    }

    /**
     * 删除图书
     * @param id
     * @return
     */
    @GetMapping("/deleteBook")
    public SaResult deleteBook(@RequestParam Long id){
        return bookService.deleteBook(id);
    }

    /**
     * 根据id查询书籍内容
     * @param bookId
     * @return
     */
    @GetMapping("/fileByBookId")
    public SaResult fileByBookId(@RequestParam Long bookId){
        return bookService.fileByBookId(bookId);
    }

    /**
     * 分页
     */

}

